package com.lifeng.fastssmr.web.controller.base;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.ui.Model;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;

public abstract class BaseController {
	public HttpServletRequest request;
	public HttpServletResponse response;
	public HttpSession session;
	public Model model;
	/**
	 * 数据绑定
	 * @param binder
	 */
	@InitBinder
	public void initBinder(WebDataBinder binder) {
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		dateFormat.setLenient(true);
		binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
	}
	
	/**
	 * 获取request，response,session,model
	 */
	@ModelAttribute
	protected void getHttpRequestAndResponse(HttpServletRequest request,
			HttpServletResponse response,HttpSession session,Model model){
		this.request = request;
		this.response = response;
		this.session = session;
		this.model = model;
	}
	
	
}
